<template>
  <div id="aCoursesList" class="bg-fa of">
    <!-- /课程详情 开始 -->
    <section class="container">
      <section class="path-wrap txtOf hLh30">
        <a href="\" title class="c-999 fsize14">首页</a>
        \
        <a href="\course" title class="c-999 fsize14">课程列表</a>
        \
        <span class="c-333 fsize14">{{courselist.title}}</span>
      </section>
      <div>
        <article class="c-v-pic-wrap" style="height: 357px;">
          <section class="p-h-video-box" id="videoPlay">
            <img v-if="isImg(courselist.cover)" src="@/static/timg.jpg" :alt="courselist.title" class="dis c-v-pic" style="width: 620px;height: 346px;">
            <img v-else :src="courselist.cover" :alt="courselist.title" class="dis c-v-pic" style="width: 620px;height: 346px;">
          </section>
        </article>
        <aside class="c-attr-wrap">
          <section class="ml20 mr15">
            <h2 class="hLh30 txtOf mt15">
              <span class="c-fff fsize24">{{courselist.title}}</span>
            </h2>
            <section class="c-attr-jg">
              <span class="c-fff">价格：</span>
              <b class="c-yellow" style="font-size:24px;">￥{{courselist.price}}</b>
            </section>
            <section class="c-attr-mt c-attr-undis">
              <span class="c-fff fsize14">主讲： {{courselist.teacherName+"      "}}</span>
            </section>
            <section class="c-attr-mt of">
              <span class="ml10 vam">
                <em class="icon18 scIcon"></em>
                <a class="c-fff vam" title="收藏" href="#" >收藏</a>
              </span>
            </section>
            <section class="c-attr-mt">
              <a href="#" title="立即观看" class="comm-btn c-btn-3">立即观看</a>
            </section>
          </section>
        </aside>
        <aside class="thr-attr-box">
          <ol class="thr-attr-ol clearfix">
            <li>
              <p>&nbsp;</p>
              <aside>
                <span class="c-fff f-fM">购买数</span>
                <br>
                <h6 class="c-fff f-fM mt10">{{courselist.buyCount}}</h6>
              </aside>
            </li>
            <li>
              <p>&nbsp;</p>
              <aside>
                <span class="c-fff f-fM">课时数</span>
                <br>
                <h6 class="c-fff f-fM mt10">{{courselist.lessonNum}}</h6>
              </aside>
            </li>
            <li>
              <p>&nbsp;</p>
              <aside>
                <span class="c-fff f-fM">浏览数</span>
                <br>
                <h6 class="c-fff f-fM mt10">{{courselist.viewCount}}</h6>
              </aside>
            </li>
          </ol>
        </aside>
        <div class="clear"></div>
      </div>
      <!-- /课程封面介绍 -->
      <div class="mt20 c-infor-box">
        <article class="fl col-7">
          <section class="mr30">
            <div class="i-box">
              <div>
                <section id="c-i-tabTitle" class="c-infor-tabTitle c-tab-title">
                  <a name="c-i" class="current" title="课程详情">课程详情</a>
                </section>
              </div>
              <article class="ml10 mr10 pt20">
                <div>
                  <h6 class="c-i-content c-infor-title">
                    <span>课程介绍</span>
                  </h6>
                  <div class="course-txt-body-wrap">
                    <section class="course-txt-body" v-html="courselist.description">
                    </section>
                  </div>
                </div>
                <!-- /课程介绍 -->
                <div class="mt50">
                  <h6 class="c-g-content c-infor-title">
                    <span>课程大纲</span>
                  </h6>
                  <section class="mt20">
                    <div class="lh-menu-wrap">
                      <menu id="lh-menu" class="lh-menu mt10 mr10">
                        <ul>
                          <!-- 文件目录 -->
                          <li class="lh-menu-stair" v-for="(item,index) in chapterVideo" :key="index">
                            <a href="javascript: void(0)" :title="item.title" class="current-1">
                              <em class="lh-menu-i-1 icon18 mr10"></em>{{item.title}}
                            </a>
                            <ol class="lh-menu-ol" style="display: block;">
                              <li class="lh-menu-second ml30" v-for="(items,i) in item.children" :key="i">
                                <a :href="'/player/'+items.videoSourceId" target="_blank">
                                  <!--  <span class="fr">
                                    <i class="free-icon vam mr10">免费试听</i>
                                  </span> -->
                                  <em class="lh-menu-i-2 icon16 mr5">&nbsp;</em>{{items.title}}
                                </a>
                              </li>

                            </ol>
                          </li>
                        </ul>
                      </menu>
                    </div>
                  </section>
                </div>
                <!-- /课程大纲 -->
                <!-- 评论  -->
                <div class="comment">
                   <section id="c-i-tabTitle" class="c-infor-tabTitle c-tab-title">
                     <a name="c-i" class="current" title="课程评论">课程评论</a>
                   </section>
                   <div class="comment-inp">
                     <el-input
                       type="textarea"
                       placeholder="请输入内容"
                       v-model="Comment.content"
                       maxlength="60"
                       show-word-limit
                     >

                     </el-input>
                     <el-button @click="onrelease">默认按钮</el-button>

                   </div>

                   <div class="comment-subject">
                     	<ul>
                     		<li v-for="(item,index) in EduCommentlist.items" :key="index">
                          <div class="comment-subject-img">
                            <img :src="item.avatar" >
                          </div>
                          <div class="comment-subject-text">
                            <h4>
                              {{item.nickname}}
                            </h4>
                            <i>{{item.gmtCreate}}</i>
                            <p>
                              {{item.content}}
                            </p>
                          </div>
                           <div class="comment-subject-remove" v-if="user.id == item.memberId" >
                             <i class="el-icon-delete" @click="delComment(item.id)"></i>
                           </div>
                        </li>
                     	</ul>
                   </div>

                </div>
                <div v-if="EduCommentlist.total>8">
                   <div class="paging">
                     <!-- undisable这个class是否存在，取决于数据属性hasPrevious -->
                     <a
                       :class="{undisable: !EduCommentlist.hasPrevious}"
                       href="#"
                       title="首页"
                       @click.prevent="pageComments(1)">首</a>
                     <a
                       :class="{undisable: !EduCommentlist.hasPrevious}"
                       href="#"
                       title="前一页"
                       @click.prevent="pageComments(EduCommentlist.current-1)">&lt;</a>
                     <a
                       v-for="page in EduCommentlist.pages"
                       :key="page"
                       :class="{current: EduCommentlist.current == page, undisable: EduCommentlist.current == page}"
                       :title="'第'+page+'页'"
                       href="#"
                       @click.prevent="pageComments(page)">{{ page }}</a>
                     <a
                       :class="{undisable: !EduCommentlist.hasNext}"
                       href="#"
                       title="后一页"
                       @click.prevent="pageComments(EduCommentlist.current+1)">&gt;</a>
                     <a
                       :class="{undisable: !EduCommentlist.hasNext}"
                       href="#"
                       title="末页"
                       @click.prevent="pageComments(EduCommentlist.pages)">末</a>

                 </div>
                </div>
                <!-- /评论  -->
              </article>
            </div>
          </section>
        </article>
        <aside class="fl col-3">
          <div class="i-box">
            <div>
              <section class="c-infor-tabTitle c-tab-title">
                <a title href="javascript:void(0)">主讲讲师</a>
              </section>
              <section class="stud-act-list">
                <ul style="height: auto;">
                  <li>
                    <div class="u-face">
                      <a :href="/teacher/+courselist.teacherId">
                        <img :src="courselist.avatar" width="50" height="50" alt>
                      </a>
                    </div>
                    <section class="hLh30 txtOf">
                      <a class="c-333 fsize16 fl" href="#">{{courselist.teacherName}}</a>
                    </section>
                    <section class="hLh20 txtOf">
                      <span class="c-999">{{courselist.intro}}</span>
                    </section>
                  </li>
                </ul>
              </section>
            </div>
          </div>
        </aside>
        <div class="clear"></div>
      </div>
    </section>
    <!-- /课程详情 结束 -->
  </div>
</template>

<script>
  import {addComment,pageComment,removeComment,getFrontCourseInfo} from '~/http'
  import cookie from "js-cookie"
  import '~/assets/css/comment.css'

export default {
  data(){
    return{
        courselist:{},
        chapterVideo:[],
        Comment:{},
        EduCommentlist:{},
        user:{}
    }
  },
  created() {
    this.getAll()
    this.pageComments()
    let ucenter = cookie.get("get_ucenter")
    if(ucenter){
       this.user = JSON.parse(ucenter);
       
    }
  },
  methods:{
    getAll(){
      if(this.$route.params.id){
        getFrontCourseInfo(this.$route.params.id).then(res=>{

          this.courselist = res.data.courseWebVo
          this.chapterVideo = res.data.chapterVideoByCourseId
          this.Comment.courseId = this.$route.params.id
        })

      }

    },
    pageComments(page = 1){
      pageComment(page,8,this.$route.params.id).then(res=>{
        this.EduCommentlist = res.data.comment
      })
    },
    onrelease(){
      if(!this.Comment.content){this.$message.error('你没有评论'); return false}
      if(this.user.id){
         this.Comment.teacherId = this.courselist.teacherId
         this.Comment.memberId = this.user.id
         this.Comment.nickname = this.user.nickname
         this.Comment.avatar = this.user.avatar
         addComment(this.Comment).then(res=>{
            this.$notify({
              title: '评论成功',
              message: '这是一条成功的提示消息',
              type: 'success'
            });
            this.Comment = {}
            this.pageComments()
         })
      }else{
         this.$message.error('你没有登录');
      }

    },
    isImg(text){
      text = text + ""
      if(text.includes("https"))return false
      return true
    },
    delComment(id){
      removeComment(id).then(res=>{
        this.$notify({
          title: '删除成功',
          message: '这是一条成功的提示消息',
          type: 'success'
        });
        this.pageComments()
      })
    }
  }
};
</script>
